<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public $service;
    public $host;
    public $perPage;

    public function __construct()
    {
        $this->host       = config('site.domain');
        $this->limit      = config('site.limit');
        $this->each_chunk = config('site.each_chunk');
    }

    /**
     * @param $data
     * @param string $msg
     * @param int $code
     * @return JsonResponse
     */
    public function success($data = '', $msg = '', $code = 200)
    {
        $result = [
            'code' => $code,
            'data' => $data,
            'msg'  => $msg,
        ];

        return response()->json($result);
    }

    /**
     * @param $msg
     * @param string $data
     * @param int $code
     * @return JsonResponse
     */
    public function error($msg, $code = 400, $data = '')
    {
        $result = [
            'code' => $code,
            'data' => $data,
            'msg'  => $msg,
        ];

        return response()->json($result);
    }
}
